package com.ossjk.api.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.Condition;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.ossjk.core.base.controller.BaseController;
import com.ossjk.core.util.CommonUtil;
import com.ossjk.oa.accounting.service.ICwCapitalsService;
import com.ossjk.oa.attendance.service.IAtdreportService;
import com.ossjk.oa.attendance.service.IAttendanceService;
import com.ossjk.oa.finance.service.IReimburseService;
import com.ossjk.oa.finance.service.ISubreimburseService;
import com.ossjk.oa.system.entity.Attachment;
import com.ossjk.oa.system.service.IAttachmentService;
import com.ossjk.oa.system.service.IDepartmentService;
import com.ossjk.oa.system.service.IEmployeePostService;
import com.ossjk.oa.system.service.IEmployeeService;
import com.ossjk.oa.system.service.IPostService;
import com.ossjk.oa.system.service.ITokenService;
 

@RestController
@RequestMapping("/api")
public class ApiController2 extends BaseController {
 
	@Autowired
	private ICwCapitalsService iCwCapitalsService;
	@Autowired
	private IEmployeeService iEmployeeService;
	@Autowired
	private IPostService iPostService;
	@Autowired
	private IEmployeePostService iEmployeePostService;
	@Autowired
	private IDepartmentService iDepartmentService;
	@Autowired
	private ITokenService iTokenService;
	@Autowired
	private IReimburseService iReimburseService;
	@Autowired
	private ISubreimburseService iSubreimburseService;
	@Autowired
	private IAttachmentService iAttachmentService;
	@Autowired
	private IAttendanceService iAttendanceService;
	@Autowired
	private IAtdreportService iAtdreportService;
	
	@RequestMapping(value = "attImg")
	public void getImg(String attid, HttpServletResponse response) throws IOException {


		Attachment att=    iAttachmentService.selectById(attid);

		response.setContentType("image/jpeg/jpg/png/gif/bmp/tiff/svg");
		String imgPath = URLDecoder.decode( att.getUrl() + File.separator +  att.getFile(), "utf-8");
		System.out.println("imgPath=" + imgPath);
		File file = new File(imgPath);
		if ( file.exists() ) {
			FileInputStream in = new FileInputStream(file);
			OutputStream os = response.getOutputStream();
			byte[] b = new byte[1024];
			while (in.read(b) != -1) {
				os.write(b);
			}
			in.close();
			os.flush();
			os.close();
		}
	}
	
	///////////加班API////////////////
	@GetMapping("/lsOvt")
	public Object list(String did, String eid, String mth, String rwst ) {
		Wrapper wrapper = Condition.create().isWhere(true).eq("a.type", "1").eq("a.isdelete", "1").orderBy("a.rwst", true).orderBy("a.crtm", true);

		if (!CommonUtil.isBlank(did)) {
			wrapper.eq("a.did", did);
		}else if (!CommonUtil.isBlank(eid)) {
			wrapper.eq("a.eid", eid);
		} else {
			// 默认查询自己
			if (CommonUtil.isBlank(did)) {
				wrapper.eq("a.eid", getCurrnetUserId());
			}
		}
		
		if (!CommonUtil.isBlank(rwst)) {
			wrapper.eq("a.rwst", rwst);
		}
		
		//page = iAtdreportService.selectVoPage(page, wrapper);
		
		//return responseSuccess(page);
		return responseSuccess();
	}
	
	
    ///////////加班API END//////////// 
	
	
	
}
